perm filename APPEN.LSP[E84,JMC] blob sn#762069 filedate 1984-07-16 generic text, type C, neo UTF8
COMMENT āŠ—   VALID 00002 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	appen.lsp[e84,jmc]	Locally dirty append
C00004 ENDMK
CāŠ—;
;;;appen.lsp[e84,jmc]	Locally dirty append

	This version of APPEND called APPEND1 has the following
properties:

	1. It is iterative, so it cannot run out of push down list if
properly compiled or interpreted.

	2. It uses the dirty pseudofunction RPLACD.

	3. Its output is clean in that no Lisp variable other than
the local variables of the function can have its value changed
by the execution of APPEND1.  For this reason we call APPEND1 {\it locally
dirty}, or to put it positively, {\it globally clean}.  It may be
conjectured that a Prolog compiler, would generate approximately
the same code as a Lisp compiler using this definition provided it
were given the standard Prolog definition of APPEND and told what
were the input and output variables.

(defun append1 (u v)
       (if (null u)
	   v
	   (let ((w (cons (car u) v))) (append1a w w (cdr u)))))

(defun append1a (val w u)
       (if (null u)
	   val
	   (append1a val
		     (cdr (rplacd w (cons (car u) v)))
		     (cdr u))))

(append1 '(a b) '(c d))